"""
wifi任务模块
日期: 2024/12/19
"""


import utime

from settings import ProductionConfig as current_config



class TaskWifi():
    def __init__(self, at):
        self.at = at

    # 初始化
    def init(self):
        if self.at.cwmode != 1:  # 如果不是station模式,就设置
            self.at.set_cwmode(1)
            
        info_ip_mac = self.at.ip_mac
        if self.at.ip_mac[2] == '0.0.0.0':  # 如果未获取到ip,代表未联网,连接ap
            if self.at.connect_to_ap(current_config.WIFI_SSID, current_config.WIFI_PASSWORD):
                utime.sleep(2)  # 如果连上,要等待几秒
                info_ip_mac = self.at.ip_mac
            else:
                print('连接wifi失败')
                
            
        #    print(self.at.ip_mac)  # 获取网络信息
        #    print(self.at.ap_info)  # 获取ap信息
            
            

    # 该方法仅用于调试
    def get_response(self):
        return self.at.get_response()


    
